import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver

class TemplateSquare:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/template"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetTemplateSquare(self):
        # 查找页面元素
        title = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[1]/div/span').text
        assert title == "模板广场"
        # 添加模板
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[1]/span/div/div/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # 关闭添加模板
        self.driver.find_element(By.XPATH,'//*[@id="editor"]/div[2]/div[1]/div[2]/div/button[1]').click()
        # 公共库
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[3]/div/div[1]/div[1]/div/div[1]').click()
        # 私有库
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[3]/div/div[1]/div[1]/div/div[2]').click()
        # 分类选择
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[1]').click()
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[2]').click()
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/form/div[1]/div[2]/div/div/div/div/div/div/span[3]').click()

        # 搜索模板
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/input').send_keys("测试")
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/span/span/span/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()

